package com.sf.dlb.controller;


import com.sf.dlb.bean.UserReportBean;
import com.sf.dlb.constant.ResponseConstant;
import com.sf.dlb.jpa.model.TokenEntity;
import com.sf.dlb.service.UserReportServiceBase;
import com.sf.dlb.utils.GsonUtils;
import com.sf.dlb.utils.ResultVOUtil;
import com.sf.dlb.vo.ResultVO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;


/**
 * 举报
 * Created by jing.tan on 2018/12/10.
 */
@RestController
@RequestMapping(value = "/v1/report")
public class UserReportController {
    private static Logger logger = LoggerFactory.getLogger(UserReportController.class);
    @Autowired
    private UserReportServiceBase userReportService;
    /**
     * 添加举报
     * @returns
     */
    @PostMapping(value = "/add")
    @ResponseBody
    public Object addReport(HttpServletRequest request,@RequestBody UserReportBean userReportBean) {
        logger.info("addReport start ");
        ResultVO resultVO=(ResultVO)request.getAttribute("token");
        if(StringUtils.isBlank(userReportBean.getReportId())){
            return ResultVOUtil.error(ResponseConstant.ERROR,"举报Id不能为空");
        }
        if(StringUtils.isBlank(userReportBean.getReportType())){
            return ResultVOUtil.error(ResponseConstant.ERROR,"举报类型不能为空");
        }
        if(StringUtils.isBlank(userReportBean.getReportDesc())){
            return ResultVOUtil.error(ResponseConstant.ERROR,"举报内容不能为空");
        }
        TokenEntity tokenEntity=(TokenEntity)resultVO.getData();
        resultVO= userReportService.addReport(tokenEntity.getUserId(),userReportBean.getReportType(),userReportBean.getReportId(),userReportBean.getReportDesc());
        logger.info("addReport response json === " + GsonUtils.getInstance().toJson(resultVO));
        return resultVO;
    }
}
